FROM centos:centos7
MAINTAINER tian.dong <tiandong19860806@126.com>

#========================install jdk========================================================================

RUN mkdir -p /opt/install/jdk
COPY soft/jdk-8u212-linux-x64.tar.gz  /opt/install/
RUN \
    tar -zxf /opt/install/jdk-8u212-linux-x64.tar.gz -C /opt/install/ && \
    mv /opt/install/jdk1.8.0_212/* /opt/install/jdk/ && \
    rm -rf /opt/install/jdk1.8.0_212 && \
	rm -rf /opt/install/jdk-8u212-linux-x64.tar.gz
ENV JAVA_HOME /opt/install/jdk
ENV CLASS_PATH $CLASS_PATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
ENV PATH $PATH:$JAVA_HOME/bin
	
#========================install nexus========================================================================

# step 1: make directory
RUN mkdir -p /opt/install
COPY soft/nexus-3.20.1-01-unix.tar.gz /opt/install/
COPY soft/nexus.sh /opt/install/

# step 2: set enviroment
ENV SONATYPE_APP_ROOT /docker_data/app/infra-system/nexus-single
ENV SONATYPE_DATA_ROOT /docker_data/data/infra-system/nexus-single
ENV NEXUS_HOME $SONATYPE_APP_ROOT/nexus
ENV SONATYPE_WORK $SONATYPE_DATA_ROOT/sonatype-work
ENV NEXUS_DATA $SONATYPE_DATA_ROOT/nexus-data
ENV NEXUS_CONTEXT ''
ENV INSTALL4J_ADD_VM_PARAMS "-Xms=256m -Xmx=256m -XX:MaxDirectMemorySize=512m -Djava.util.prefs.userRoot $NEXUS_DATA/javaprefs"
ENV PATH $PATH:$NEXUS_HOME/bin
# set nfs mapping path, also can set it in the file of deployment.
# VOLUME ["$SONATYPE_APP_ROOT", "$SONATYPE_DATA_ROOT"]

# step 3: install nexus
# 或者修改配置文件${NEXUS_HOME}/bin/nexus.rc，修改参数为"run_as_user=nexus"
USER nexus
# RUN useradd nexus
# chmod -R 777 ${NEXUS_HOME}/nexus.sh
# https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.20.1-01-unix.tar.gz
# 切记：有个安装目录".install4j"不要忘记：默认是隐藏的：mv ${SONATYPE_APP_ROOT}/.install4j
RUN \
    mkdir -p ${NEXUS_HOME} && \
    mkdir -p ${SONATYPE_WORK} && \
    mkdir -p ${NEXUS_DATA} && \
    tar -zxf /opt/install/nexus-3.20.1-01-unix.tar.gz -C ${SONATYPE_APP_ROOT} && \
    mv ${SONATYPE_APP_ROOT}/.install4j ${NEXUS_HOME}/ && \
    mv ${SONATYPE_APP_ROOT}/nexus-3.20.1-01/* ${NEXUS_HOME}/ && \
	mv ${SONATYPE_APP_ROOT}/sonatype-work/* ${SONATYPE_WORK}/ && \
    mv /opt/install/nexus.sh ${NEXUS_HOME}/ && \
    chmod -R 777 ${SONATYPE_APP_ROOT}/ && \
    chmod -R 777 ${SONATYPE_DATA_ROOT}/ && \
    chown -R nexus:nexus ${SONATYPE_APP_ROOT}/ && \
    chown -R nexus:nexus ${SONATYPE_DATA_ROOT}/ && \
    rm -rf ${SONATYPE_APP_ROOT}/nexus-3.20.1-01-unix.tar.gz && \
    rm -rf ${SONATYPE_APP_ROOT}/nexus-3.20.1-01 && \
    rm -rf ${SONATYPE_APP_ROOT}/sonatype-work
# COPY soft/nexus.conf ${NEXUS_HOME}/

# open port
EXPOSE 8081

# start application
# default account = admin; default password = admin123
# 默认密码，存放在目录 = cat /opt/install/nexus-single/sonatype-work/nexus3/admin.password 
# 默认密码 = b2801c2f-9160-484e-8fe2-ea63d15c9321
# ENTRYPOINT ["${NEXUS_HOME}/nexus.sh"]
# 启动命令 = nexus start 或 nexus run; 但是nexus start 是后台启动，不能再窗口看见实时日志; nexus run是前台启动，可以看见实时日志。
# 查看状态 = nexus status
# ENTRYPOINT ["nexus start"]
ENTRYPOINT ["nexus start"]
